<template>
    <div>
        <div style="">
            <ss17002-modal ref="ss17002Modal" @ok="reloadData"></ss17002-modal>
            <ss17012-modal ref="ss17012Modal" @ok="reloadData"></ss17012-modal>
        </div>
        <div style="margin-top: 10px">
            <Table :columns="columns" :data="tableData" :loading="Loading" border>
                <template slot-scope="{ row, index}" slot="action">
                    <Button type="success" size="small" style="margin-right: 5px" @click="handleEdit(index)">详情</Button>
                </template>
            </Table>
            <div style="margin: 10px;overflow: hidden">
                <div style="float: right;">
                    <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                          @on-change="handleTableChange" :current="pageNo"></Page>
                </div>
            </div>
        </div>
        <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
            <Button @click="prevStep">上一步</Button>
            <Button type="primary" @click="nextStep" :loading="btnLoading" style="margin-left:20px">下一步
            </Button>
        </div>
    </div>
</template>

<script>
    import ss17002Modal from './modules/Ss17002Modal.vue'
    import ss17012Modal from './modules/Ss17012Modal.vue'
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'

    export default {
        name: 'application2',
        mixins: [CommonMixin],
        components: {
            ss17002Modal, ss17012Modal
        },
        data() {
            return {
                url: {
                    list: '/api/ac/subsistence/ss17002Service/getPageList',
                    getSs11002One: '/api/ac/subsistence/ss17002Service/getOne',
                    getSs11012One: '/api/ac/subsistence/ss17012Service/getOne',
                    deleteSs11002: '/api/ac/subsistence/ss17002Service/deleteData',
                    deleteSs11012: '/api/ac/subsistence/ss17012Service/deleteData',
                    checkStep2: '/api/ac/subsistence/ss17002Service/checkPersonInfo',
                },
                dataCount: 0,
                pageSize: 10,
                familyInfo: {},
                queryParam: {},
                columns: [
                    {
                        title: '姓名',
                        key: 'azcp0003',
                        align: 'center',
                    },
                    {
                        title: '与申请人关系',
                        key: 'azcp0517_name',
                        align: 'center',
                        width: 130
                    },
                    {
                        title: '性别',
                        key: 'azcp0004_name',
                        align: 'center',
                    },
                    {
                        title: '证件号码',
                        key: 'azcp0001',
                        align: 'center',
                        width: 190
                    },
                    {
                        title: '民族',
                        key: 'azcp0007_name',
                        align: 'center',
                    },
                    {
                        title: '健康状况',
                        key: 'azcp0009_name',
                        align: 'center',
                        width: 120
                    },
                    {
                        title: '劳动能力丧失情况',
                        key: 'azcp0502_name',
                        align: 'center',
                        width: 170
                    },
                    {
                        title: '查验状态',
                        key: 'azcp0578_name',
                        align: 'center',
                    },
                    {
                        title: '保障状态',
                        key: 'type_name',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        slot: 'action',
                        align: 'center',
                        fixed: 'right',
                    }
                ],
                tableData: [],
                Loading: false,
                btnLoading: false,
                ss11001Id: this.$parent.familyInfo.ss11001Id,
                ss11002Id: this.$parent.familyInfo.ss11002Id,
            }
        },
        methods: {
            prevStep() {
                this.$emit('prevStep')
            },
            nextStep() {
                let that = this;
                that.btnLoading = true
                let url = that.url.checkStep2
                let dataParam = {};
                dataParam.ssca0087 = that.familyInfo.ssca0087;
                dataParam.azcp0500 = that.ss17001Id;
                dataParam.ssca0016 = that.familyInfo.ssca0016;
                dataParam.ssca0002 = that.familyInfo.ssca0002;
                dataParam.ss12001Id = that.familyInfo.ss12001Id;
                let yjab0012 = that.familyInfo.yjab0012;
                if(yjab0012=='01'||yjab0012=='02'||yjab0012=='04'){
                    //预警处置 已处置、维持现状不校验
                    this.$emit('nextStep')
                }else
                if (dataParam.ssca0016 != '300' && dataParam.ssca0016 != '500' && dataParam.ssca0016 != '501') {
                    postAction(url, dataParam).then((res) => {
                        if (res.data.errcode == 9999) {
                            this.$Message.error(res.data.errmsg);
                        } else {
                            if (res.data.data.code == 1) {
                                this.$emit('nextStep')
                            } else {
                                that.$Message.error(res.data.data.msg);
                            }
                        }
                    }).finally(() => {
                        that.btnLoading = false
                    });
                } else {
                    //停救、区内迁移和跨区迁移，不校验checkPersonInfoSs17
                    this.$emit('nextStep');
                }
            },
            handleEdit(index) {
                let that = this;
                let record = that.tableData[index];
                let url = null;
                let dataParam = {};
                dataParam.id = record.id;
                if (record.id) {
                    if (record.type == '1') {
                        url = that.url.getSs11002One
                        postAction(url, dataParam).then((res) => {
                            if (res.data.data.code == 1) {
                                res.data.data.data.ss12001Id = that.familyInfo.ss12001Id
                                that.$refs.ss17002Modal.edit(res.data.data.data)
                            } else {
                                that.$Message.error(res.data.data.msg);
                            }
                        });
                    } else {
                        url = that.url.getSs11012One
                        postAction(url, dataParam).then((res) => {
                            if (res.data.data.code == 1) {
                                that.$refs.ss17012Modal.edit(res.data.data.data)
                            } else {
                                that.$Message.error(res.data.data.msg);
                            }
                        });
                    }
                } else {
                    that.$Message.error('请选择操作数据');
                }
            },
            reloadData() {
                let that = this;
                that.queryParam.azcp0500 = that.ss11001Id;
                that.loadData();
            },
        },
        created() {
            let that = this;
            that.familyInfo = that.$parent.familyInfo;
            that.queryParam.azcp0500 = that.familyInfo.ss17001Id;
            //that.queryParam.azcp0500='ab77b34f1ecb4aa28b0e2b95c0db868d';
            that.loadData();
            //如是停救，operationType=300,则页面不可编辑
            if (that.$parent.familyInfo.ssca0016 == '300' || that.$parent.familyInfo.ssca0016 == '500' || that.$parent.familyInfo.ssca0016 == '501') {
                that.disabledForStop = true
            }else if(that.$parent.familyInfo.yjab0012=='01'||that.$parent.familyInfo.yjab0012=='02' ||that.$parent.familyInfo.yjab0012=='04'){
                //预警处置 已处置、维持现状 不可编辑数据
                that.disabledForStop = true
            }
        },
    }
</script>

<style scoped>

</style>
